<template>
	<view class="login">
		<view class="uni-padding-wrap">
			<view class="name">系统登录</view>
			<form :data="form">
				<view class="uni-form-item uni-column uni-inline-item">
					<label class="title">账号</label>
					<input class="uni-input" v-model.trim="form.email" placeholder="请输入账号" />
				</view>
				<view class="uni-form-item uni-column uni-inline-item">
					<label class="title">密码</label>
					<input type="password" class="uni-input" v-model.trim="form.password" placeholder="请输入密码" />
				</view>
				<view class="uni-btn-v"><button class="submit" type="primary" @click="submit">登录</button></view>
			</form>
		</view>
		<view class="register" @click="goToRegister()">
			没有账号？
			<font>立即注册</font>
		</view>
	</view>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
import { get, post, showToast } from '@/static/utils/index';
export default {
	data() {
		return {
			form: {
				email: '',
				password: ''
			}
		};
	},
	onLoad() {},
	created() {},
	methods: {
		goToRegister(){
			
				uni.navigateTo({
					url: `/pages/login/register`
				});
		},
		//提交
		submit() {
			let formData = this.form;
			if (!formData.email) {
				showToast('请填写账号');
				return;
			}
			if (!formData.password) {
				showToast('请填写密码');
				return;
			}
			this.$store.dispatch('login', Object.assign({}, formData)).then(res => {
				if (res.code == 200) {
					showToast('登陆成功');
					uni.switchTab({
						url: `/pages/info/index`
					});
				} else {
					showToast(res.msg);
				}
			});
		},

		//身份证正面上传
		chooseSharePic() {
			uni.chooseImage({
				count: 1,
				sizeType: ['original', 'compressed'],
				sourceType: ['album', 'camera'],
				success: res => {
					let tempPath = res.tempFilePaths[0];
					let tempFile = res.tempFiles[0];
					//上传文件
					uploadFile(tempPath, { ext: 'p' }).then(res => {
						this.form.idcard_p = res.data.src;
					});
				}
			});
		},
		//身份证反面上传
		chooseSharePicN() {
			uni.chooseImage({
				count: 1,
				sizeType: ['original', 'compressed'],
				sourceType: ['album', 'camera'],
				success: res => {
					let tempPath = res.tempFilePaths[0];
					let tempFile = res.tempFiles[0];

					//上传文件
					uploadFile(tempPath, { ext: 'n' }).then(res => {
						this.form.idcard_n = res.data.src;
					});
				}
			});
		},
		//银行卡照片
		chooseSharePicBank() {
			uni.chooseImage({
				count: 1,
				sizeType: ['original', 'compressed'],
				sourceType: ['album', 'camera'],
				success: res => {
					let tempPath = res.tempFilePaths[0];
					let tempFile = res.tempFiles[0];
					//上传文件
					uploadFile(tempPath, { ext: 'n' }).then(res => {
						this.form.bank_thumb = res.data.src;
					});
				}
			});
		},
		idcardChange() {
			this.$store.dispatch('getInfo', Object.assign({}, { idcard: this.form.idcard })).then(res => {
				if (res.code == 200) {
					this.form.idcard_p = this.form.idcard_p ? this.form.idcard_p : res.data.idcard_p;
					this.form.idcard_n = this.form.idcard_n ? this.form.idcard_n : res.data.idcard_n;
					this.form.name = this.form.name ? this.form.name : res.data.name;
					this.form.phone = this.form.phone ? this.form.phone : res.data.phone;
					this.form.remark = this.form.remark ? this.form.remark : res.data.remark;
					this.form.bank = this.form.bank ? this.form.bank : res.data.bank;
					this.form.bank_thumb = this.form.bank_thumb ? this.form.bank_thumb : res.data.bank_thumb;
					this.form.open_bank = this.form.open_bank ? this.form.open_bank : res.data.open_bank;
				}
			});
		}
	}
};
</script>

<style>
.login {
	min-height: 100vh;
	background-color: #ffffff;
}
.name {
	text-align: center;
	color: #5881ff;
	font-size: 46upx;
	margin-bottom: 10vh;
}
.label {
	padding-top: 20upx;
	margin-bottom: 20upx;
	font-size: 32upx;
	color: #9c9c9c;
}

.submit {
	background-color: #5881ff;
}
.register {
	text-align: center;
	cursor: pointer;
}
.register font {
	color: #5881ff;
}

.uni-form-item {
	border-bottom: 1px solid #ececec;
}
label {
	display: inline;
	vertical-align: middle;
}
.uni-padding-wrap {
	padding-top: 15vh;
}
</style>
